<template>
    <div class="ranking-page">
    <div v-if="showList">
        <div class="top">
            <router-link to="/home" tag="div" class="left">
                <img src="../assets/images/back_b_icon.png" alt="">
            </router-link>
            <div class="top-title">排行榜</div>
        </div>
        <div class="bg">
            <img src="../assets/images/leaderboard_background.png" alt="">
            <div class="re-title">推荐榜单</div>
        </div>
        <div class="recommend" v-if="countlists">
            <div class="re-item" v-for="(item) in countlists" :key="item.rankingId" @click="showPub(item.rankingId,item.rankingType)" :style="{ 'background-image': 'url('+item.rankingCover+')' }" v-lazy:background-image="item.rankingCover">
                <h4>{{item.rankingTitle}}</h4>
                <img src="../assets/images/leaderboard_top_white.png" alt="">
            </div>
        </div>
        <div class="selected" v-if="selective" :style="{ 'background-image': 'url('+selective.rankingCover+')' }">
            <div class="mask" @click="showPub(selective.rankingId,selective.rankingType)">
            <h4>{{selective.rankingTitle}}</h4>
            <img src="../assets/images/leaderboard_top_yellow.png" alt="">
            </div>
        </div>
        <div class="selected-lists" v-if="labelLists">
            <div class="s-title">精选榜单</div>
            <div class="lists-con">
                <div class="con-item" v-for="(item) in labelLists" :key="item.rankingId" @click="showPub(item.rankingId,item.rankingType)">
                    <img src="../assets/images/leaderboard_top_yellow.png" alt="">
                    <div class="img" :style="{'background-image':'url('+item.rankingCover+')'}" v-lazy:background-image="item.rankingCover">
                        
                    </div>
                    <div class="img-mask">
                        <h4>{{item.rankingName}}</h4>
                    </div>
                </div>
                
            </div>
        </div>
    </div>
    <van-loading size="24px" class="loading" v-if="!showList" type="spinner">正在拼命加载中...</van-loading>
    </div>
</template>

<script>
import {getRankingData} from '../api/ranking'
    export default {
        data() {
            return {
                showList: false,
                countlists:null,//推荐榜单
                selective:null,//编辑精选推荐榜
                labelLists:null,//精选榜单
                rankLists:null,
            };
        },
        methods: {
            //获取排行榜列表详情
            getRankingFun(){
                getRankingData().then(data=>{
                    console.log(data);
                    if (data.data) {
                        setTimeout(() => {
                            this.showList = true
                        }, 500);
                        //推荐榜单
                        let count = data.data.filter(item=>item.rankingType=='count')
                        this.countlists = count[0].recipeRanking
                        //编辑精选推荐榜
                        let selectiveType = data.data.filter(item=>item.rankingType=='selective')
                        this.selective = selectiveType[0].recipeRanking[0]
                        // 精选榜单
                        let label = data.data.filter(item=>item.rankingType=='label')
                        this.labelLists = label[0].recipeRanking
                        
                    }else{
                        setTimeout(() => {
                            this.$toast("加载失败")
                            this.$router.push("/home")
                        }, 500);
                    }
                })
            },
            showPub(id,type){
                this.$router.push({path:"/publicRanking",query:{id,type}});
            },
        },
        created() {
            this.getRankingFun()
        },
    }
</script>

<style lang="less" scoped>
.ranking-page{
    width: 100%;
    height: 100%;
    overflow: hidden;

    .top{
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 99;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        .left{
            margin:0 20px;
            &>img{
                width: 12px;
                height: 20px;
            }
        }
        .top-title{
            margin-left: 8px;
            font-size: 17px;
            font-weight: bold;
            letter-spacing: 0.8px;
        }
    }
    .bg{
        position: relative;
        .re-title{
            width: 110px;
            height: 30px;
            background-color: #fff;
            color: #000;
            font-size: 16px;
            font-weight: bold;
            text-align: center;
            line-height: 30px;
            border-top-left-radius: 12px;
            border-top-right-radius: 12px;
            position: absolute;
            bottom: 0;
            left: 0;
        }

    }
    .recommend{
        padding: 10px 10px;
        display: flex;
        justify-content: space-evenly;
        .re-item{
            position: relative;
            display: inline-block;
            width: 110px;
            height: 80px;
            // background-image: linear-gradient(45deg,#ffdf78,#fcb017);
            background-position: center center;
            background-repeat: no-repeat;
            background-size: cover;
            border-radius: 9px;
            padding: 10px;
            box-sizing: border-box;

            &>h4{
                font-size: 15px;
                font-weight: bold;
                letter-spacing: 0.8px;
                margin-top: 18px;
                margin-left: 5px;
                color: #9b6914;
            }
            &>img{
                width: 60px;
                height: 17px;
                position: absolute;
                top: 0;
                left: 0;
            }
        }
    }
    .selected{
        width: 92%;
        height: 80px;
        background-image: url('../assets/images/245708746.jpg');
        background-repeat: no-repeat;
        background-position: center;
        background-size: cover;
        position: relative;
        margin: 0 auto;
        border-radius: 10px;
        overflow: hidden;

        .mask{
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;   
            margin: auto;
            background-image: linear-gradient(90deg,#423f36,transparent);

            &>img{
            width: 60px;
            height: 17px;
            position: absolute;
            top: 0;
            left: 0;
            }
            &>h4{
                line-height: 80px;
                color: #fff;
                font-weight: bold;
                font-size: 15px;
                margin-left: 15px;
            }
        }
    }
    .selected-lists{
        width: 100%;
        box-sizing: border-box;
        padding: 10px 15px 0 15px;

        .s-title{
            margin: 5px 0 15px 10px;
            font-size: 16px;
            font-weight: bold;
            letter-spacing: 0.8px;
        }
        .lists-con{
 
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;
           .con-item{
                width: 105px;
                height: 110px;
                position: relative;
                border-radius: 10px;
                overflow: hidden;
                margin: 5px 0 10px 0;
                
                &>img{
                    width: 60px;
                    height: 17px;
                    position: absolute;
                    top: 0;
                    left: 0;
                }
                .img{
                    width: 100%;
                    height: 100%;
                    background-image: url("https://pic.ecook.cn/web/259531730.jpg!wl280");
                    background-repeat: no-repeat;
                    background-position: center;
                    background-size: cover;

                }
                .img-mask{
                    width: 100%;
                    height: 30px;
                    background-color: rgba(0, 0, 0, 0.4);
                    position: absolute;
                    bottom: 0;
                    text-align: center;
                    line-height: 30px;
                    color: #fff;
                    font-size: 13px;
                    font-weight: bold;
                    letter-spacing: 0.8px;
                }
           }

        }
    }
}
.loading {
  position: fixed;
  top: 50px;
  left: 0;
  right: 0;
  bottom: 100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>